var basePath = getBasePath();
//1.对传感器名称进行格式化
function sensorNameFormat(sensorName) {
    let sensorNameShow;
    if (sensorName.startsWith("T") || sensorName.startsWith("环温")) {
        sensorNameShow = sensorName + "(℃)";
    } else if ("电压" == sensorName) {
        sensorNameShow = sensorName + "(V)";
    } else if ("电流" == sensorName) {
        sensorNameShow = sensorName + "(A)";
    } else if ("功率" == sensorName) {
        sensorNameShow = sensorName + "(W)";
    } else if ("耗电量" == sensorName) {
        sensorNameShow = sensorName + "(kw.h)";
    } else if ("频率" == sensorName) {
        sensorNameShow = sensorName + "(Hz)";
    } else if ("湿温" == sensorName) {
        sensorNameShow = sensorName + "(℃)";
    } else {
        sensorNameShow = sensorName;
    }
    return sensorNameShow;

}

//2.获取所有选择的传感器名称
function getAllSelectSensorName(primaryKey,testunitno) {
    //yyi 写死
   /* var primaryKey = "2017-11-1611:17:211";*/
    var primarykey = $.cookie("nowprimarykey");
    var labcode = $.cookie("labcode");
    var testunitno="1"
    $.ajax({
        type: "get",
        url: "http://localhost/consumer/CurveInfoAPI/getAllSelectSensorName",
        data:{
            primaryKey:primaryKey,
            testunitno:testunitno
        },
        success: function (msg) {
            var item = "<thead>" + "<tr class='alert-success'>" +
                "<td><strong>日期</strong></td>"+ "<td><strong>时间</strong></td>";
            $("#table_content tr").eq(1).remove();
            for (var i = 0; i < msg.length; i++) {
                //拼接字符串
                item = item + "<td><strong>" + sensorNameFormat(msg[i].name) + "</strong></td>";
            }
            item = item + "</tr>" + "</thead>";
            $("#table_content").append(item);
        },
        error: function (e) {
            alert("网页发生错误：", e, "error");
        }
    });
}

//3.获取数据列表
function getNewDataList(labcode,testunitno,pageNum) {
    let layerid=layer.msg('加载中', {
        icon: 16,
        shade: 0.4,
        time:false //取消自动关闭
    });
    //yyi写死
    var labcode = "Haierrefrigerator20151214";
    var testunitno="1";
    var pageNum = "1";
    $.ajax({
        type: "get",
        url: "http://localhost/consumer/CurveInfoAPI/getAllTestDataVo",
        data:{
            labcode:labcode,
            testunitno:testunitno,
            pageNum:pageNum
        },
        success: function (msg) {
            layer.close(layerid);//手动关闭
            var item = "<tbody>";
            //$("#table_content tr:not(:first)").remove();
            $("#table_content tbody tr").remove();
            for (var i = 0; i < msg.list.length; i++) {
                //传感器编号列表
                var sensorNoList = msg.list[i].sensorNoList;
                //传感器名称列表
                var sensorNameList = msg.list[i].sensorNameList;
                //传感器数据列表
                var sensorValueList = msg.list[i].sensorValueList;
                if (i % 2) {
                    //拼接字符串
                    item = item + "<tr class='info'>" +
                        "<td>" + msg.list[i].date + "</td>" +
                        "<td>" + msg.list[i].time + "</td>";
                    //拼接传感器的值
                    for (var j = 0; j < sensorValueList.length; j++) {
                        item = item + "<td>" + sensorValueList[j] + "</td>";
                    }
                    item = item + "</tr>";
                }
                else {
                    //拼接字符串
                    item = item + "<tr>" +
                        "<td>" + msg.list[i].date + "</td>" +
                        "<td>" + msg.list[i].time + "</td>";
                    //拼接传感器的值
                    for (var j = 0; j < sensorValueList.length; j++) {
                        item = item + "<td>" + sensorValueList[j] + "</td>";
                    }
                    item = item + "</tr>";
                }

            }
            item = item + "</tbody>";
            $("#table_content").append(item);
            var pageNum = msg.pageNum;
            var total = msg.total;
            var pages= msg.pages;
            //设置页码
            $("#total").text(total);
            $("#pageNum").text(pageNum);
            $("#pages").text(pages);
        },
        error: function (e) {
            alert("网页发生错误：", e, "error");
        }
    });
}